package com.assessment.servermanager.controller;


import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.util.ObjectUtil;
import com.assessment.servermanager.commen.controller.BaseController;
import com.assessment.servermanager.commen.entity.AjaxResult;
import com.assessment.servermanager.commen.entity.PageQuery;
import com.assessment.servermanager.commen.page.TableDataInfo;
import com.assessment.servermanager.entity.TbDoc;
import com.assessment.servermanager.entity.bo.TbDocBo;
import com.assessment.servermanager.entity.vo.TbDocVo;
import com.assessment.servermanager.oss.entity.vo.SysOssVo;
import com.assessment.servermanager.service.ITbDocService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author jiajia
 * @date 2023-08-28
 */
@RestController
@RequestMapping("/doc")
public class TbDocController extends BaseController {
    @Autowired
    private ITbDocService tbDocService;

    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/list")
    public TableDataInfo<TbDocVo> list(TbDocBo tbDocBo, PageQuery pageQuery) {
        return tbDocService.selectTbDocList(tbDocBo,pageQuery);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbDoc tbDoc) {
       /* List<TbDoc> list = tbDocService.selectTbDocList(tbDoc);
        ExcelUtil<TbDoc> util = new ExcelUtil<TbDoc>(TbDoc.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");*/
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tbDocService.selectTbDocById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PostMapping
    public AjaxResult add(@RequestBody TbDoc tbDoc) {
        return toAjax(tbDocService.insertTbDoc(tbDoc));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PutMapping
    public AjaxResult edit(@RequestBody TbDoc tbDoc) {
        return toAjax(tbDocService.updateTbDoc(tbDoc));
    }

    /**
     * 删除【请填写功能名称】
     */

    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tbDocService.deleteTbDocByIds(ids));
    }

    /**
     * 上传文件
     */
    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public AjaxResult uploadFile(@RequestPart("file") MultipartFile file){
        if (ObjectUtil.isNull(file)) {
            return AjaxResult.error("上传文件不能为空");
        }
        SysOssVo ossVo = tbDocService.uploadFile(file);
        return AjaxResult.success(ossVo);
    }
}
